package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.ImUserGroupDeleteDto;
import com.ruoyi.system.domain.dto.ImUserGroupDto;
import com.ruoyi.system.domain.dto.ImUserGroupUpdateDto;
import com.ruoyi.system.domain.vo.ImUserGroupDetailVo;
import com.ruoyi.system.domain.vo.ImUserGroupUserVo;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ImUserGroup;
import com.ruoyi.system.service.IImUserGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 群组Controller
 * 
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/system/group")
public class ImUserGroupController extends BaseController
{
    @Autowired
    private IImUserGroupService imUserGroupService;

    /**
     * 新增群组
     * @param groupDto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addGroup(@RequestBody ImUserGroupDto groupDto){
        imUserGroupService.addGroup(groupDto);
        return AjaxResult.success();
    }

    /**
     * 群组列表
     * @param groupName
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo groupList(String groupName){
        return imUserGroupService.groupList(groupName);
    }

    /**
     * 群详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public AjaxResult groupDetail(@PathVariable Long id){
        ImUserGroupDetailVo detailVo=imUserGroupService.groupDetail(id);
        return AjaxResult.success(detailVo);
    }

    /**
     * 修改信息
     * @param updateDto
     * @return
     */
    @PostMapping("/update")
    public AjaxResult updateGroup(@RequestBody ImUserGroupUpdateDto updateDto){
        imUserGroupService.updateGroup(updateDto);
        return AjaxResult.success();

    }

    /**
     * 成员列表
     * @param groupId
     * @return
     */
    @GetMapping("/userList")
    public TableDataInfo userList(Long groupId){

        return imUserGroupService.userList(groupId);

    }

    /**
     * 解散群组
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Long id){
        imUserGroupService.delete(id);
        return AjaxResult.success();
    }

    /**
     * 删除群成员
     * @param deleteDto
     * @return
     */
    @PostMapping("deleteUser")
    public AjaxResult deleteUser(@RequestBody ImUserGroupDeleteDto deleteDto){
        imUserGroupService.deleteUser(deleteDto);
        return AjaxResult.success();
    }




}
